package com.ruoyi.badRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.badRecord.domain.BadRecord;
import com.ruoyi.badRecord.service.IBadRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 不良记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */

@RestController
@RequestMapping("/badRecord/record")
@Api(tags = "不良记录", description = "不良记录")
public class BadRecordController extends BaseController
{
    @Autowired
    private IBadRecordService badRecordService;

    /**
     * 查询不良记录列表
     */
    @ApiOperation("查询不良记录列表")
    @PreAuthorize("@ss.hasPermi('badRecord:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BadRecord badRecord)
    {
        startPage();
        List<BadRecord> list = badRecordService.selectBadRecordList(badRecord);
        return getDataTable(list);
    }

    /**
     * 导出不良记录列表
     */
    @ApiOperation("导出不良记录列表")
    @PreAuthorize("@ss.hasPermi('badRecord:record:export')")
    @Log(title = "不良记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BadRecord badRecord)
    {
        List<BadRecord> list = badRecordService.selectBadRecordList(badRecord);
        ExcelUtil<BadRecord> util = new ExcelUtil<BadRecord>(BadRecord.class);
        util.exportExcel(response, list, "不良记录数据");
    }

    /**
     * 获取不良记录详细信息
     */
    @ApiOperation("获取不良记录详细信息")
    @PreAuthorize("@ss.hasPermi('badRecord:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(badRecordService.selectBadRecordById(id));
    }

    /**
     * 新增不良记录
     */
    @ApiOperation("新增不良记录")
    @PreAuthorize("@ss.hasPermi('badRecord:record:add')")
    @Log(title = "不良记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BadRecord badRecord)
    {
        return toAjax(badRecordService.insertBadRecord(badRecord));
    }

    /**
     * 修改不良记录
     */
    @ApiOperation("修改不良记录")
    @PreAuthorize("@ss.hasPermi('badRecord:record:edit')")
    @Log(title = "不良记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BadRecord badRecord)
    {
        return toAjax(badRecordService.updateBadRecord(badRecord));
    }

    /**
     * 删除不良记录
     */
    @ApiOperation("删除不良记录")
    @PreAuthorize("@ss.hasPermi('badRecord:record:remove')")
    @Log(title = "不良记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(badRecordService.deleteBadRecordByIds(ids));
    }
}
